package cmd

import (
	"bbs125Check/RROcr"
	"bbs125Check/bbs125"
	"bbs125Check/config"
	"context"
	"gitee.com/kaylee595/gretry"
	"github.com/kaylee595/tracerr"
)

func loginBBS125(ctx context.Context, bbs125Client *bbs125.Client, RROcrClient *RROcr.Client) error {
	recognizeResult, err := gretry.Do(ctx, func(ctx context.Context) (*RROcr.RespRecognize, error) {
		// 获取极验参数
		geeTest, err := bbs125Client.GeeTest(ctx)
		if err != nil {
			return nil, tracerr.Wrap(err)
		}
		// 获取极验validate
		return tracerr.Wrap1(RROcrClient.Recognize(&RROcr.ReqRecognize{
			Referer:   "https://bbs.125.la/",
			Gt:        geeTest.Gt,
			Challenge: geeTest.Challenge,
		}))
	})
	if err != nil {
		return tracerr.Wrap(err)
	}
	// 登录精易论坛
	_, err = bbs125Client.Login(ctx, config.Cfg.Username, config.Cfg.Password, bbs125.ReqLoginGeeTest{
		Challenge: recognizeResult.Data.Challenge,
		Validate:  recognizeResult.Data.Validate,
	})
	return tracerr.Wrap(err)
}
